
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="./web3.min.js"></script>  
  <title>Title</title>
</head>
<body>
<script>
  var eth,accounts;
  
  function run() {
    if (typeof web3 == 'undefined') {
      return alert("metamask not found!");
    }

    eth = new Web3(web3.currentProvider).eth;

    eth.getAccounts(function(err, _accounts) {
      if(err) {
        console.log(err);
        return alert("getAccounts fails");
      }

      console.log(_accounts);
      $('body').append("metamask 地址:<br/>"+JSON.stringify(_accounts, null, 4) + "<br/><button onclick='sendTx()'>发送测试交易</button>")
      accounts = _accounts;
    });
  }

  function sendTx() {
    var txParams = {
      chainId: 1,
      data: "",
      from: accounts[0],
      to: "0x653739A3Da0022399FfBc9F2C395c7dC885cb158",
      // gasLimit: "0x5208",
      // gasPrice: "0x098bca5a00",
      // nonce: "0x00",
      value: "0x0de0b6b3a7640000"
    };

    eth.sendTransaction(txParams, function(err, txid){
      if(err) {
        console.log(err);
        return alert("发送交易失败!");
      }
      console.log(txid);
      $('body').append('<br/>交易hash:<a href="https://ropsten.etherscan.io/tx/'+txid+'">'+txid+'<>')
    });
  }

  run();
</script>
</body>
</html>
